package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.domain.AdminSmDataAuth;
import cn.com.yusys.yusp.admin.service.AdminSmDataAuthService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @项目名称: yusp-admin
 * @类名称: AdminSmDataAuthResource
 * @类描述: 数据权限配置
 * @功能描述:
 * @创建人: weimei1@yusys.com.cn
 * @创建时间: 2017-12-19 11:31
 * @修改备注:
 * @修改记录: 修改时间 修改人员 修改原因
 *        -------------------------------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2017宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/adminsmdataauth")
public class AdminSmDataAuthResource extends CommonResource<AdminSmDataAuth, String> {
    @Autowired
    private AdminSmDataAuthService adminSmDataAuthService;

    @Override
    protected CommonService getCommonService() {
        return this.adminSmDataAuthService;
    }

    /**
     * @方法名称: getDataAuthInfo
     * @方法描述: 查询数据权限表
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/getdataauth")
    public ResultDto<List<Map<String, Object>>> getDataAuthInfo(QueryModel queryModel) {
        List<Map<String, Object>> list = adminSmDataAuthService.getDataAuthInfo(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * @方法名称: createDataAuth
     * @方法描述: 新增数据权限信息
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/createdataauth")
    public ResultDto<Integer> createDataAuth(@RequestBody AdminSmDataAuth adminSmDataAuth) {
        int result = this.adminSmDataAuthService.createDataAuth(adminSmDataAuth);
        ResultDto<Integer> resultDto = new ResultDto<>();
        if(result >= 1){
            resultDto.setMessage("新增数据权限 authId："+adminSmDataAuth.getAuthId());
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: editDatuAuth
     * @方法描述: 修改数据权限信息
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/edtidataauth")
    public ResultDto<Integer> editDatuAuth(@RequestBody AdminSmDataAuth adminSmDataAuth) {
        int result = this.adminSmDataAuthService.editDatuAuth(adminSmDataAuth);
        ResultDto<Integer>  resultDto = new ResultDto<>();
        if(result >= 1){
            resultDto.setMessage("修改数据权限信息");
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: getAuthTmpl
     * @方法描述: 查询控制点可用数据权限模板
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/authtmplquery")
    public ResultDto<List<Map<String, Object>>> getAuthTmpl(QueryModel queryModel) {
        List<Map<String, Object>> list = adminSmDataAuthService.getAuthTmpl(queryModel);
        return new ResultDto<List<Map<String, Object>>>(list);
    }

    /**
     * @方法名称: deleteDataAuth
     * @方法描述: 删除数据权限信息
     * @参数与返回说明:
     * @算法描述:
     */
    @PostMapping("/deletedataauth/{ids}")
    protected ResultDto<Integer> deleteDataAuth(@PathVariable String ids) {
        int result = adminSmDataAuthService.deleteDataAuth(ids);
        ResultDto<Integer> resultDto = new ResultDto<>();
        if(result >= 1){
            resultDto.setMessage("删除数据权限信息 ids："+ids);
        }
        resultDto.setData(result);
        return resultDto;
    }

    /**
     * @方法名称: getTree
     * @方法描述: 左侧树查询
     * @参数与返回说明:
     * @算法描述:
     */
    @GetMapping("/treequery")
    public ResultDto<List<Map<String, Object>>> getTree(@RequestParam(required = false)String nodeId) {
        List<Map<String, Object>> list = adminSmDataAuthService.getTree(nodeId);
        return new ResultDto<List<Map<String, Object>>>(list.size(),list);
    }
}
